package multidraw.model;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.util.Vector;

public class TextBox extends RectangleShape implements TwoEndBoundaryShape {
	private StringBuilder text;
	//private Point startingPoint;
	
	protected Font font = new Font("Serif", Font.BOLD, 24);
	
	final static int DEFAULT_WIDTH = 100; //100 pixels
	
	final static int DEFAULT_HEIGHT = 40; //20 pixels
	
	public TextBox(Point startingPoint, Color c, long id) {
		super(startingPoint.x, startingPoint.y - DEFAULT_HEIGHT, 
				DEFAULT_WIDTH, DEFAULT_HEIGHT, c, id);
		penColor = c;
		text = new StringBuilder();		
	}
	
	

	@Override
	public void draw(Graphics g, boolean selected) {
		//super.drawOutline(g);
		// TODO Auto-generated method stub
		Graphics2D g2 = (Graphics2D) g;
		
		//change the pen
		Color c = g2.getColor();

		g2.setColor(penColor);
		
		g2.setFont(font);
		
		int fontSize = g2.getFontMetrics().getHeight();
		g2.drawString(text.toString(), (int) leftX, (int) (topY + fontSize));
		g2.setColor(c);
	}

	@Override
	public void drawOutline(Graphics g) {		
		// TODO Auto-generated method stub
		Graphics2D g2 = (Graphics2D) g;
		
		
		
		//change the pen
		Color c = g2.getColor();

		g2.setColor(penColor);
		
		g2.setFont(font);
		
		int fontSize = g2.getFontMetrics().getHeight();
		
		width = g2.getFontMetrics().bytesWidth(text.toString().getBytes(), 
				0, text.toString().length());
		height = fontSize; 
		super.drawOutline(g);
		
		
		g2.drawString(text.toString(), (int) leftX, (int) (topY + fontSize));
		g2.setColor(c);
	}
	
	@Override
	public boolean isNearControlPoint(Point p) {
		// TODO Auto-generated method stub
		return false;
	}

	public void addChar(char ch) {
		text.append(ch);
		width = 4 * text.toString().length();
	}

}
